﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCameraByMouse : MonoBehaviour
{
    private float f_Horizontal;
    private float f_Vertical;
    private float leap_Fidld;
    private float f_MouseX;
    private float f_MouseY;

    public float f_up = 21370;    //摄像机上升的最大高度
    public float f_down = -903;  //摄像机下降的最小高度
    public float f_left = -22657;  //摄像机左移限制
    public float f_right = 20211; //摄像机右移限制
    public float f_front = 33897; //摄像机前进限制
    public float f_back = -41021;  //摄像机后退限制


    public float f_HorizontalSpeed = 80f;   //水平移动速度
    public float f_VerticalSpeed = 80f;     //垂直移动速度
    public float f_forwardSpeed = 4000f;      //滚轴移动速度

    private Vector3 v_Limit;          //摄像机坐标

    public void Update()
    {

        if (!StartUIController._instance.b_isMask)
        {
            f_Horizontal = Input.GetAxis("Horizontal");
            f_Vertical = Input.GetAxis("Vertical");
            leap_Fidld = Input.GetAxis("Mouse ScrollWheel");
            f_MouseX = Input.GetAxis("Mouse X");
            f_MouseY = Input.GetAxis("Mouse Y");
            if (f_Horizontal != 0 || f_Vertical != 0 || leap_Fidld != 0
                || (Input.GetMouseButton(2) && (f_MouseX != 0 || f_MouseY != 0)))
            {
                transform.position += transform.right * f_Horizontal * f_HorizontalSpeed;
                transform.position += transform.up * f_Vertical * f_VerticalSpeed;
                transform.position += transform.forward * leap_Fidld * f_forwardSpeed;
                if (Input.GetMouseButton(2))
                {
                    transform.position -= transform.right * f_MouseX * f_HorizontalSpeed;
                    transform.position -= transform.up * f_MouseY * f_VerticalSpeed;
                }
                v_Limit = transform.position;
                if (transform.position.x <= f_left)
                    v_Limit.x = f_left;
                if (transform.position.x >= f_right)
                    v_Limit.x = f_right;
                if (transform.position.y <= f_down)
                    v_Limit.y = f_down;
                if (transform.position.y >= f_up)
                    v_Limit.y = f_up;
                if (transform.position.z <= f_back)
                    v_Limit.z = f_back;
                if (transform.position.z >= f_front)
                    v_Limit.z = f_front;
                transform.position = v_Limit;
            }
        }

    }
}